package com.myadapter;

import java.util.ArrayList;
import java.util.List;

import com.bean.TopPager;
import com.example.lizhiinformation.R;
import com.ownload.Httputil;
import com.ownload.Httputil.OnNetWorkBitmpResponse;
import com.ownload.Httputil.OnNetWorkRespones;
import com.tools.Path_URL;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class FrontPage_Topadapter extends PagerAdapter {
	private ArrayList<View> views;
	private List<TopPager> topPagers;
	private Context context;
	
	
	public FrontPage_Topadapter(List<TopPager> topPagers,  Context context) {
		super();
		this.topPagers = topPagers;
		this.context = context;
		LayoutInflater inflater = LayoutInflater.from(context);
		views=new ArrayList<View>();
		for (int i = 0; i <topPagers.size(); i++) {
			View view = inflater.inflate(R.layout.toppaget_item, null);
			TextView subject = (TextView) view.findViewById(R.id.tv_topPager_subject);
			final ImageView icon = (ImageView) view.findViewById(R.id.iv_topPager_icon);
			Httputil.OnworkBitmaDown(Path_URL.IMAGEURL+topPagers.get(i).getPhoto(),new OnNetWorkBitmpResponse() {

				@Override
				public void OK(Bitmap bitmap) {
					// TODO Auto-generated method stub
					icon.setImageBitmap(bitmap);
				}
				
				@Override
				public void ERROR(String error) {
					// TODO Auto-generated method stub
					
				}
			});
			subject.setText(topPagers.get(i).getSubject());
			views.add(view);
		}
			
	}
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = views.get(position);
		container.addView(view);
		return view;
	}
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		container.removeView(views.get(position));
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return views.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0==arg1;
	}
	
}
